﻿using System;
using System.ServiceProcess;
using Microsoft.Practices.Unity;
using SleepManagement.Controllers;

namespace SleepManagement
{
    static class Program
    {
        static void Main()
        {
            var container = new UnityContainer();
            try
            {
                container.RegisterType<IAnnoyingManager, AnnoyingManager>(LifetimeManagerBuilder());
                container.RegisterType<ISleepManager, SleepManager>(LifetimeManagerBuilder());
            }
            catch (Exception e)
            {
                CustomLogManager.LogException(e);
                throw;
            }
            
            var servicesToRun = new ServiceBase[] { new SleepManagementService(container.Resolve<ISleepManager>()) };
            ServiceBase.Run(servicesToRun);
        }

        private static LifetimeManager LifetimeManagerBuilder()
        {
            return new PerThreadLifetimeManager();
        }
    }
}
